package com.chinanet.netelementmodel;


import com.chinanet.entry.netelement.Attr;
import com.chinanet.entry.netelement.AttrType;
import com.chinanet.entry.netelement.WorkInterFace;
import com.chinanet.utils.pon.FH_SocketClient;
import com.chinanet.utils.pon.HW_Socket_AttrsIn;
import com.chinanet.utils.pon.OperationType;

import java.util.HashMap;
import java.util.Map;

/**
 * @description Created by jwing on 2018/1/11.
 * 烽火FTTN/B北向指令 ONU复位（ONU不具有管理IP）
 */
public class FH_FTTNB_ResetONU_NoManager implements WorkInterFace {
    @Override
    public String getName() {
        return "烽火FTTN/B北向指令 ONU复位（ONU不具有管理IP）";
    }

    @Override
    public String getDesciption() {
        return "";
    }

    @Override
    public int getVersion() {
        return 0;
    }

    @Override
    public Attr[] getInAttrs() {
        // TODO: 指令未确认
        Attr[] in=new Attr[4];
        in[0] = new Attr("OLTID", "OLT的ID", AttrType.TYPE_String, true);
        in[1] = new Attr("PONID", "PON口ID", AttrType.TYPE_String, true);
        in[2] = new Attr("ONUID", "ONU标识，可以按ONU_NAME/MAC/LOID/ONU_NUMBER取值，用于唯一标识PON口的ONU", AttrType.TYPE_String, true);
        in[3] = new Attr("ONUPORT", "ONU端口，格式为“机架-框-槽-端口号”，没有则使用NA代替，如0框0槽0端口为NA-0-0-0。", AttrType.TYPE_String, true);
        return in;
    }

    @Override
    public Attr[] getOutAttrs() {
        Attr[] out = new Attr[2];
        out[0] = new Attr("flag", "操作是否成功，1：成功，0：失败", AttrType.TYPE_Int, true);
        out[1] = new Attr("log", "日志文件", AttrType.TYPE_String, true);
        return out;
    }

    @Override
    public Map<String, Object> init(Map<String, Object> data) {
        Map<String, Object> outmap = new HashMap<>();
        String ip ="134.103.69.183";
        int port = 3337;
        FH_SocketClient fhclient = new FH_SocketClient(ip, port);
        HW_Socket_AttrsIn attrsin = new HW_Socket_AttrsIn();
        attrsin.setUsername("FH");
        attrsin.setPassword("FH123456");
        attrsin.setOLTID((String) data.get("OLTID"));
        attrsin.setPONID((String) data.get("PONID"));
        attrsin.setONUID((String) data.get("ONUID"));
        attrsin.setONUPORT((String) data.get("ONUPORT"));
        Map<String, Object> inmap = fhclient.init(attrsin,
                OperationType.TYPE_FHFTTHB_RESETONU_NOMANAGER);
        boolean flag = (Boolean) inmap.get("flag");
        if(flag){
            outmap.put("flag", 1);
        }else{
            outmap.put("flag", 0);
        }
        outmap.put("log", inmap.get("log"));
        return outmap;
    }
}
